/*
 * JDialogPropiedadesComponente.java
 *
 * Copyright 2011 Universidad Francisco de Paula Santander (UFPS).
 * Todos los Derechos Reservados.
 * Created on 24/01/2011, 06:13:44 PM
 */

package com.ufps.cuatro.vistas.representacion;

import java.util.Observable;
import java.util.Observer;

import javax.swing.table.TableColumn;

import org.jdesktop.application.Action;

import com.ufps.cuatro.CuatroApp;
import com.ufps.cuatro.modelo.asistente.UtilAsistente;
import com.ufps.cuatro.modelo.representacion.componente.Componente;
import com.ufps.cuatro.util.Bandera;
import com.ufps.cuatro.util.Utileria;
import com.ufps.cuatro.util.editor.ColumnCellEditorDistribucionGridBagConstraintsColumnValue;
import com.ufps.cuatro.util.editor.ColumnCellEditorPropertiesDisponibleColumnCodeGet;
import com.ufps.cuatro.util.editor.ColumnCellEditorPropertiesDisponibleColumnCodeSet;
import com.ufps.cuatro.util.editor.ColumnCellEditorPropertiesDisponibleColumnValue;
import com.ufps.cuatro.util.editor.ColumnCellEditorPropertiesInternaColumnCodeGet;
import com.ufps.cuatro.util.editor.ColumnCellEditorPropertiesInternaColumnCodeSet;
import com.ufps.cuatro.util.model.MyTableModelProperties;
import com.ufps.cuatro.util.render.ColumnCellRendererDistribucionGridBagConstraintsColumnValues;
import com.ufps.cuatro.util.render.ColumnCellRendererPropertiesDisponibleColumnCodeGet;
import com.ufps.cuatro.util.render.ColumnCellRendererPropertiesDisponibleColumnCodeSet;
import com.ufps.cuatro.util.render.ColumnCellRendererPropertiesDisponibleColumnValues;
import com.ufps.cuatro.util.render.ColumnCellRendererPropertiesInternaColumnCodeGet;
import com.ufps.cuatro.util.render.ColumnCellRendererPropertiesInternaColumnCodeSet;
import com.ufps.cuatro.controlador.render.UtilRender;

/**
 *<i><b>JDialogPropiedadesComponente:</b></i> Este Cuadro de dialog Administra
 * las Propiedades de Configuración de los Controles Swing que son representados
 * por los Componentes Generados.
 * 
 * @author Carlos A. Torres C. - Dolly E. Guerrero. <https://code.google.com/p/tesis4dor/>
 * @version 1.0 24/01/2011
 * @see javax.swing.JDialog
 * @see Observer
 */
public class JDialogPropiedadesComponenteTemp extends javax.swing.JDialog implements Observer{
    private static final long serialVersionUID = -374176212040399568L;
    
    private Componente objComponente;
    private Object objParent;

    /** Creates new form JDialogPropiedadesComponente
     * @param parent @DefinicionParametro
     * @param modal  @DefinicionParametro
     */
    public JDialogPropiedadesComponenteTemp(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setIconImage(Utileria.leerIconoAppEnImagen(Utileria.MODO_16x16).getImage());
    }

    /**
     * @DefinicionMetodo
     * @param objParent @DefinicionParametro
     * @param objComponente @DefinicionParametro
     */
    public JDialogPropiedadesComponenteTemp(Object objParent, Componente objComponente) {
        super(CuatroApp.getApplication().getMainFrame() , true);
        initComponents();
        this.setIconImage(Utileria.leerIconoAppEnImagen(Utileria.MODO_16x16).getImage());
        this.objParent = objParent;        
        this.cargarPropiedades(objComponente);
    }
    
    private void cargarPropiedades(Componente objComponente){        
        this.objComponente = objComponente;
        this.jTextFieldClassPath.setText(objComponente.getStrClassPath());
        this.jLabelComponenteContenedor.setText(objComponente.getObjComponenteBase().getStrAlias());        
        crearTablaPropiedadesDisponibles(objComponente); 
        crearTablaPropiedadesInternas(objComponente); 
        crearTablaDistribucionGridBagConstraints(objComponente);
    }

    private void crearTablaDistribucionGridBagConstraints(Componente objComponente) {
        this.jTableDistribucion.setModel(UtilAsistente.crearTablaPropiedadesDistribucionComponente(objComponente));
        this.jTableDistribucion.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        TableColumn objColumnValor = this.jTableDistribucion.getColumn(MyTableModelProperties.NAME_COLUMN_VALUES);
        objColumnValor.setCellRenderer(new ColumnCellRendererDistribucionGridBagConstraintsColumnValues());
        objColumnValor.setCellEditor(new ColumnCellEditorDistribucionGridBagConstraintsColumnValue());                    
        this.jTableDistribucion.setRowHeight(24);
    }

    private void crearTablaPropiedadesDisponibles(Componente objComponente) {
        this.jTablePropiedadesUsuario.setModel(UtilAsistente.crearTablaPropiedadesDisponibles(objComponente.getObjPropiedadesDisponibles()));
        this.jTablePropiedadesUsuario.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        
        TableColumn objColumnValor = this.jTablePropiedadesUsuario.getColumn(MyTableModelProperties.NAME_COLUMN_VALUES);
        objColumnValor.setCellRenderer(new ColumnCellRendererPropertiesDisponibleColumnValues(objComponente));
        objColumnValor.setCellEditor(new ColumnCellEditorPropertiesDisponibleColumnValue(objComponente));                
                
        TableColumn objColumnSet = this.jTablePropiedadesUsuario.getColumn(MyTableModelProperties.NAME_COLUMN_VIEWSET);
        objColumnSet.setCellRenderer(new ColumnCellRendererPropertiesDisponibleColumnCodeSet());
        objColumnSet.setCellEditor(new ColumnCellEditorPropertiesDisponibleColumnCodeSet());                
        
        TableColumn objColumnGet = this.jTablePropiedadesUsuario.getColumn(MyTableModelProperties.NAME_COLUMN_VIEWGET);
        objColumnGet.setCellRenderer(new ColumnCellRendererPropertiesDisponibleColumnCodeGet());
        objColumnGet.setCellEditor(new ColumnCellEditorPropertiesDisponibleColumnCodeGet());
        this.jTablePropiedadesUsuario.setRowHeight(24);        
    }
    
    
    private void crearTablaPropiedadesInternas(Componente objComponente) {
        this.jTablePropiedadesSistema.setModel(UtilAsistente.crearTablaPropiedadesInternas(objComponente.getObjPropiedadesInternas()));
        this.jTablePropiedadesSistema.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        
        TableColumn objColumnSet = this.jTablePropiedadesSistema.getColumn(MyTableModelProperties.NAME_COLUMN_VIEWSET);
        objColumnSet.setCellRenderer(new ColumnCellRendererPropertiesInternaColumnCodeSet());
        objColumnSet.setCellEditor(new ColumnCellEditorPropertiesInternaColumnCodeSet());                
        
        TableColumn objColumnGet = this.jTablePropiedadesSistema.getColumn(MyTableModelProperties.NAME_COLUMN_VIEWGET);
        objColumnGet.setCellRenderer(new ColumnCellRendererPropertiesInternaColumnCodeGet());
        objColumnGet.setCellEditor(new ColumnCellEditorPropertiesInternaColumnCodeGet());
        this.jTablePropiedadesSistema.setRowHeight(24);        
    }
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldClassPath = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabelComponenteContenedor = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTablePropiedadesUsuario = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTablePropiedadesSistema = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableDistribucion = new javax.swing.JTable();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton2 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(JDialogPropiedadesComponenteTemp.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setIconImage(null);
        setName("Form"); // NOI18N
        setResizable(false);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextFieldClassPath.setEditable(false);
        jTextFieldClassPath.setText(resourceMap.getString("jTextFieldClassPath.text")); // NOI18N
        jTextFieldClassPath.setName("jTextFieldClassPath"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabelComponenteContenedor.setBackground(resourceMap.getColor("jLabelComponenteContenedor.background")); // NOI18N
        jLabelComponenteContenedor.setText(resourceMap.getString("jLabelComponenteContenedor.text")); // NOI18N
        jLabelComponenteContenedor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabelComponenteContenedor.setName("jLabelComponenteContenedor"); // NOI18N
        jLabelComponenteContenedor.setOpaque(true);

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTablePropiedadesUsuario.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jTablePropiedadesUsuario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Propiedad", "Valor", "..."
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTablePropiedadesUsuario.setToolTipText(resourceMap.getString("jTablePropiedadesUsuario.toolTipText")); // NOI18N
        jTablePropiedadesUsuario.setCellSelectionEnabled(true);
        jTablePropiedadesUsuario.setName("jTablePropiedadesUsuario"); // NOI18N
        jTablePropiedadesUsuario.setRowHeight(24);
        jTablePropiedadesUsuario.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jTablePropiedadesUsuario);

        jTabbedPane1.addTab(resourceMap.getString("jScrollPane1.TabConstraints.tabTitle"), jScrollPane1); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jTablePropiedadesSistema.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Propiedad", "Set", "Get"
            }
        ));
        jTablePropiedadesSistema.setName("jTablePropiedadesSistema"); // NOI18N
        jScrollPane3.setViewportView(jTablePropiedadesSistema);

        jTabbedPane1.addTab(resourceMap.getString("jScrollPane3.TabConstraints.tabTitle"), jScrollPane3); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTableDistribucion.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Propiedad", "Valor"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableDistribucion.setName("jTableDistribucion"); // NOI18N
        jScrollPane2.setViewportView(jTableDistribucion);

        jTabbedPane1.addTab(resourceMap.getString("jScrollPane2.TabConstraints.tabTitle"), jScrollPane2); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldClassPath, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                            .addComponent(jLabelComponenteContenedor, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE))))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelComponenteContenedor)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldClassPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                .addContainerGap())
        );

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(JDialogPropiedadesComponenteTemp.class, this);
        jButton1.setAction(actionMap.get("aplicarCambios")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setName("jButton1"); // NOI18N
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        jButton2.setAction(actionMap.get("cancelarCambios")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setName("jButton2"); // NOI18N
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton2);

        jSeparator2.setName("jSeparator2"); // NOI18N
        jToolBar1.add(jSeparator2);

        jButton3.setAction(actionMap.get("help")); // NOI18N
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setName("jButton3"); // NOI18N
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JDialogPropiedadesComponenteTemp dialog = new JDialogPropiedadesComponenteTemp(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    /**
     * @DefinicionMetodo
     */
    @Action
    public void aplicarCambios() {
        Bandera objBandera = new Bandera();
        objBandera.addObserver((Observer) objParent);
        objBandera.setEstado(Bandera.PROPIEDADES_ACTUALIZADAS);                
        objBandera.notificar();  
        dispose();
    }

    /**
     * @DefinicionMetodo
     */
    @Action
    public void cancelarCambios() {
        String strMsg = Utileria.leerRecursoTexto("Utileria.msg.salir.window");
        String strTitle = Utileria.leerRecursoTexto("Utileria.app.name");        
        if(Utileria.confirmarOrden(CuatroApp.getApplication().getMainFrame(), strMsg, strTitle)){
            dispose();
        }
    }
    
    public void update(Observable o, Object arg) {
        throw new UnsupportedOperationException(java.util.ResourceBundle.getBundle("com/ufps/cuatro/vistas/representacion/resources/JDialogPropiedadesComponente").getString("NOT SUPPORTED YET."));
    }

    @Action
    public void help() {
        UtilRender.openDialogHelp(JDialogPropiedadesComponenteTemp.class, getTitle());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabelComponenteContenedor;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTableDistribucion;
    private javax.swing.JTable jTablePropiedadesSistema;
    private javax.swing.JTable jTablePropiedadesUsuario;
    private javax.swing.JTextField jTextFieldClassPath;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
